﻿using System;

namespace Framework.Scene
{
    /// <summary>
    /// 场景管理类
    /// </summary>
    public class SceneManager : ISceneManager, IModule
    {
        private ILoadSceneAgent m_LoadSceneAgent = null;
 
        public void AddLoadSceneAgent(ILoadSceneAgent agent)
        {
            if (agent == null) return;
            m_LoadSceneAgent = agent;
            m_LoadSceneAgent.Init();
        }
        public void LoadScene(int sceneId)
        {
            if (m_LoadSceneAgent == null) return;
            m_LoadSceneAgent.LoadScene(sceneId);
        }
        public void LoadScene(string sceneName)
        {
            if (m_LoadSceneAgent == null) return;
            m_LoadSceneAgent.LoadScene(sceneName);
        }
        public void LoadSceneAsync(int sceneId, LoadSceneCallback callback)
        {
            if (m_LoadSceneAgent == null) return;
            m_LoadSceneAgent.LoadSceneAsync(sceneId, callback);
        }
        public void LoadSceneAsync(string sceneName, LoadSceneCallback callback)
        {
            if (m_LoadSceneAgent == null) return;
            m_LoadSceneAgent.LoadSceneAsync(sceneName, callback);
        }

        public int GetSceneOperationProgress() {
            return m_LoadSceneAgent.GetLoadingProcess();
        }

        public void ActivationScene() {
            m_LoadSceneAgent.AllowSceneActivation();
        }
        public int Priority
        {
            get
            {
                return ModulePriority.ScenePriority;
            }
        }
        public void Init()
        {
            
        }
        public void Reset()
        {
            if (m_LoadSceneAgent != null)
                m_LoadSceneAgent.Reset();
        }
        public void Destroy()
        {
            if (m_LoadSceneAgent != null)
                m_LoadSceneAgent.Destroy();
            m_LoadSceneAgent = null;
        }
        public void Update(float frameTime, float realTime)
        {
            if(m_LoadSceneAgent != null)
                m_LoadSceneAgent.OnUpdate(frameTime, realTime);
        }
    }
}
